/*
 * @Author: hkk 2812877145@qq.com
 * @Date: 2023-05-23 14:05:21
 * @LastEditors: hkk 2812877145@qq.com
 * @LastEditTime: 2023-05-23 15:55:02
 * @FilePath: \hello-word\src\unit\music_public_fn\random.js
 * @Description: 包含随机的一些方法
 * Copyright (c) 2023 by hkk, All Rights Reserved. 
 */
import storeModules from '@/store/index';
import notify from '../error/index'

/**
 * @Date: 2023-05-23 13:57:04
 * @description 为元素设置随机背景
 * @param {*} htmlEl
 */
export async function mathBarkroundPath(htmlEl){
  let data = await storeModules.dispatch('layOut/setBarkgroundPath');
  let el = document.getElementsByClassName(`${htmlEl}`)[0];
  el.style.backgroundImage = `url(${data})`;
}

/**
 * @Date: 2023-05-23 15:55:11
 * @description: 随机颜色
 * @param {*} num 个数数量
 * @return {*}
 */
export function randomColor(num){
  if(typeof num !== 'number'){
    notify('error', '参数应该为数字')
    throw new Error('参数应该为数字')
  }
  
  let randomColorList = []
  for(let i = 0; i < num; i++){
    randomColorList[i] = ('#'+Math.random().toString(16).substring(2, 8));
  }
  return randomColorList
}